<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .header {
            width: 980px;
            height: 100px;
            margin: 0 auto;
            background-color: #ccc;
            margin-bottom: 20px;
        }
        .content { 
            width: 980px;
            margin: 0 auto;
        }
        h1 {
            text-align: center;
        }
        .main {
            float: left;
            width: 599px;
            margin-right: 10px;
            border-right: 1px solid red;
        }
        .aside{
            float: left;
            width: 360px;
            height: 400px;
            background-color: #ccc;
        }
        .grid {
            box-shadow: 1px 1px 1px #333;
            border: 1px solid #333;
            margin-bottom: 10px;
            border-radius: 10px;
            padding: 10px;
            box-sizing: border-box;
        }
    </style>
</head>

<body>
    
    <div class="header"></div>
    <div class="content">
            <div class="main">
                 
            </div>
        <div class="aside"></div>
    </div>

    <!-- 模板的内容 -->
    <script type="text/template" id="moban">  
        <div class="grid">
            <h3><%= title %></h3>
            <p>发布时间：<%= time%>  作者：<%= author %></p>    
            <p><%= content %></p>
            <p><a href="#">详细信息</a></p>
        </div> 
    </script>

    <script type="text/javascript" src="./jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="./underscore-min.js"></script>
    <script type="text/javascript">
        $.get("/news",function(data,status){
            // 得到模板的内容
            var mobanstring = $("#moban").html();
            var compiled = _.template(mobanstring);  // 模板函数

            $.get("./news",function(data,status){
                for(var i=0;i<data.length;i++){
                    var compiledString = compiled(data[i]);
                    $(".main").append($(compiledString));  // 加上$ 将字符串转换为对象
                }
            })
        })
    </script>

</body>
</html>